package com.gc.frontend.web.action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.gc.frontend.service.CarService;

/**
 * 前台入口控制类
 * @author 章瑱彬 
 * 电话：15914921094
 * QQ：562800930
 * @since 2015年3月10日
 */

@Controller
@RequestMapping("/")
public class ApplicationController {

	@Autowired
	private CarService carService;

	/**
	 * 前台首页
	 * @param request
	 * @param response
	 * @return
	 * @author 章瑱彬 
	 * 电话：15914921094
	 * QQ：562800930
	 * @since 2015年3月23日
	 */
	@RequestMapping("/")
	public ModelAndView main(HttpServletRequest request, HttpServletResponse response){
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("main");
		return modelAndView;
	}

	@RequestMapping("/follow")
	public ModelAndView follow(String id) {
		Integer carId = Integer.valueOf(id);
		List<Map<String, Object>> cars = carService.selectFront(carId);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("follow");
		modelAndView.addObject("car", cars.get(0));
		return modelAndView;
	}
}
